package com.test.tinyurl.common;

/**
 * 统一返回数据格式
 */
public class ResponseResult {
    private boolean success;
    private String msg;
    private Object data;
    private String errorCode;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public static <T> ResponseResult success() {
        return success(null, null);
    }

    public static <T> ResponseResult success(String message) {
        return success(null, message);
    }

    public static <T> ResponseResult success(T data, String message) {
        ResponseResult result = new ResponseResult();
        result.setData(data);
        result.setSuccess(true);
        result.setMsg(message);
        return result;
    }

    public static <T> ResponseResult failure(String message) {
        return failure(null, message);
    }

    public static <T> ResponseResult failure(T data, String message) {
        ResponseResult result = new ResponseResult();
        result.setData(data);
        result.setSuccess(false);
        result.setMsg(message);
        return result;
    }
}
